#include "utility.h"
#include "eventHandlerTask.h"
#include "monitorTimer.h"

#include "spi/configure_device.h"
#include "spi/spi_driver.h"
#include "gpio/gwGpio.h"
#include "i2c/i2c_driver.h"
#include "hwicap/hwicap.h"
#include "mdio/mdio.h"

#define mainUART_COMMAND_CONSOLE_STACK_SIZE	( configMINIMAL_STACK_SIZE * 2UL )
#define mainUART_COMMAND_CONSOLE_TASK_PRIORITY	( configMAX_PRIORITIES - 2 )

int main( void )
{
	gw_print( " \r\n************ Start Freertos example with gpio main **************\r\n" );

	init_state();

	/* eventHandler */
	QueueHandle_t xEventQueue = NULL;
	xEventQueue = xQueueCreate(100, sizeof(Event) );
	configASSERT( xEventQueue );

	int Status;
	Status = XSpi_init();
	if (Status != XST_SUCCESS) {
		gw_print("Failed XSpi_init\r\n");
		return XST_FAILURE;
	}

	Status = init_gpio();
	if (Status != XST_SUCCESS) {
		gw_print("Failed init_gpio\r\n");
		return XST_FAILURE;
	}

	Status = IIC_axi_initialize(IIC_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		gw_print("Failed IIC_axi_initialize\r\n");
		return XST_FAILURE;
	}

	Status = InitHwIcap();
	if (Status != XST_SUCCESS) {
		gw_print("Failed InitHwIcap\r\n");
		return XST_FAILURE;
	}

	TriMode_PhySetMdioDivisor(XAE_MDIO_DIV_DFT);

	//   for( ;; )
	//   {
	//   	if(spi_configure() == 0){
	//   		break;
	//   	}
	//   }

	//   return;

	createEventHandlerTask(xEventQueue); // task1

	createSpiConfigureTask(xEventQueue); // task2 , exit

#ifndef configEnableLog
	void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority );
	vUARTCommandConsoleStart( mainUART_COMMAND_CONSOLE_STACK_SIZE, mainUART_COMMAND_CONSOLE_TASK_PRIORITY );
	/* Register the standard CLI commands. */
	void vRegisterSampleCLICommands( void );
	vRegisterSampleCLICommands();
#endif

	vTaskStartScheduler();

	gw_print(" End of Main()!\r\n ");
	for( ;; );
}



